package com.mjduan.project.goodExample;

/**
 * Hans 2017-09-16 20:24
 */
public class TrafficLight {
    private State redState;
    private State yellowState;
    private State greenState;
    private State currentState;

    public TrafficLight() {
        redState = new RedTrafficLightState(this);
        yellowState = new YellowTrafficLightState(this);
        greenState = new GreenTrafficLightState(this);
        currentState = redState;
    }

    public void setState(State state) {
        this.currentState = state;
    }

    public void changeState() {
        currentState.handleRequest();
    }

    @Override
    public String toString() {
        return currentState.toString();
    }

    public State getRedState() {
        return redState;
    }

    public State getYellowState() {
        return yellowState;
    }

    public State getGreenState() {
        return greenState;
    }

    public State getCurrentState() {
        return currentState;
    }
}
